<?php include('includes/start_session.php') ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>e-class courses</title>
    <link href="styles/site.css" rel="stylesheet" type="text/css" />
    <link href="styles/less_padding.css" rel="stylesheet" type="text/css" />

    <script src="scripts/scripts.js" type="text/javascript"></script>
</head>
<body onload="same_height()">
	<?php include('includes/header.php') ?>
        <div id="content">
            <div id="courses">
            	<?php
            		if(isset($_GET['message']) && $_GET['message'] == '1')
            			echo '<div class="center_align"><span class="success">Η αλλαγή έγινε με επιτυχία</span></div>';
            	?>
               	<h4>Όλα τα μαθήματα</h4>
                <ul class="course_list">
			<?php
				include ('./db-api/txt-db-api.php');
				include ('./includes/user_courses.php');
				include ('./includes/course_info.php');				

				$_SESSION['previous_page'] = 'courses.php';
				$db = new Database ( 'Eclass' );
				$rows = $db->executeQuery ( "SELECT Name, Id from Courses ORDER BY Name" );

				$first = true;
				while ( $rows->next() )
				{
					if($first == true)
					{
						echo '<li class="first_course">';
						$first = false;
					}
					else
						echo "<li>";
					list ( $name, $id ) = $rows->getCurrentValues();

					$profRows = $db->executeQuery(
					'SELECT Users.Name, Users.Surname
					 FROM Users, ProfessorsCourses
					 WHERE ProfessorsCourses.CourseId = ' . $id . ' AND 
					 ProfessorsCourses.ProfessorName = Users.Username');
				
					echo "<div class=\"course\">";
					echo "<a class=\"title\" href=\"course.php?id=" . $id . "\">" . $name . "</a>";
					echo "<p class=\"minor_title\">Διδάσκοντες: ";

					$first = true;
					while ( $profRows->next() )
					{
						if($first == false)
							echo ', ';
						else
							$first = false;
						list ($name, $surname) = $profRows->getCurrentValues();
						echo $name . ' ' . $surname;
					}

					echo "</p>";
					
					if(ShowProfessorAnchor($id) == true)
					{
							ShowWatchAnchor($id);
					}
					
					echo '</div>';					
					echo "</li>";
				}
			?>
	  <br />
       </ul>
	  <div class="right_align"><a href="#" class="course_anchor">
		Επιστροφή στην κορυφή</a></div>

		</div>
		</div>
	<?php include('includes/footer.php') ?>
</body>
</html>

